<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VUE学习 - 请求的数据解构赋值</title>
</head>

<body>


    <!--载入vue.js-->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <div id="Application">
        参考：Setup使用axios请求获取的值
        http://www.qb5200.com/article/533160.html<br />

        您的名字是：{{name}} <br />
        您的ID是：{{id}}<br />
    </div>
    <script>
        const app = Vue.createApp({
            setup() {
                //这里定义一个结构体，用来保存项目信息
                var Data = Vue.reactive({
                    name: "",
                    id: "",
                    age: "",
                });

                axios.get('https://rouse.npc.ink/api/data.php')
                    .then(response => {
                        const { name, id, age } = response.data;
                        Data.name = name;
                        Data.id = id;
                        Data.age = age;
                    })
                return { ...Vue.toRefs(Data) };
            },
        })

        app.mount("#Application")
    </script>

</body>

</html>